//
//  CategorDetailViewController.m
//  Coco_Music
//
//  Created by K。 on 15/6/22.
//  Copyright (c) 2015年 寇广超. All rights reserved.
//

#import "CategorDetailViewController.h"

@interface CategorDetailViewController ()

@end

@implementation CategorDetailViewController
-(void)dealloc
{
    [_myArray release];
    [_myTableView release];
    [_myImageView release];
    [_imageView release];
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor brownColor];
    self.navigationItem.title = @"乐库";
    self.myArray =[NSMutableArray array];
    self.myTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height-64) style:UITableViewStylePlain ];
    self.myTableView.separatorStyle =  UITableViewCellSeparatorStyleNone;
    self.myTableView.backgroundColor =[UIColor whiteColor];
    [self.view addSubview:self.myTableView];
    [_myTableView release];
    
    self.myTableView.delegate = self;
    self.myTableView.dataSource = self;
 
    
    self.myImageView =[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height/3)];
    [self.view addSubview:self.myImageView];
    
    
    UIVisualEffectView *visualEffct = [[UIVisualEffectView alloc]initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
    visualEffct.frame=self.myImageView.frame;
    visualEffct.alpha =1;
    [self.myImageView addSubview:visualEffct];

    self.imageView =[[UIImageView alloc]initWithFrame:CGRectMake(self.myImageView.center.x-70, self.myImageView.center.y-70 , 140, 140)];
    self.imageView.layer.masksToBounds =YES;
    self.imageView.layer.cornerRadius = 10;
    
    [visualEffct addSubview:self.imageView];
    
   
    self.myTableView.tableHeaderView = self.myImageView;
    [self getData];
    self.HUD =[MBProgressHUD showHUDAddedTo:self.view animated:YES];
    self.HUD.labelText =@"正在加载中";
    [self.HUD show:YES];
    
    
    
}
#define CateGorDetailConnect @"http://api.dongting.com/channel/channel/%ld/songs?"
#define CateGorDetailConnect1 @"size=50&page=1&app=ttpod&v=v7.9.4.2015052918&uid=&mid=iPad4%2C4&f=f320&s=s330&imsi=&hid=&splus=8.3&active=1&net=2&openudid=5df9002635a21cc5f7f660e71a16d1e35e5a04a0&idfa=B5F4461B-F9C7-4F1E-BA92-EB2E683311DF&utdid=VYEt7JjHCIUDAGowp1W3cSW3&alf=201200&bundle_id=com.ttpod.music"
-(void)getData
{
    NSString *url =[NSString stringWithFormat:CateGorDetailConnect,(long)self.SongList_id];
    NSLog(@"656145%ld",self.SongList_id);
    NSString *url1 =[NSString stringWithFormat:url,CateGorDetailConnect1];
   [AFN_block NSString:url1 Blokc:^(id request) {
       NSMutableDictionary *dic =[NSMutableDictionary dictionaryWithDictionary:request];
       NSLog(@"NSMutabkeDictionary = %@",url1);
       NSMutableArray *dataArray =[dic objectForKey:@"data"];
       for (NSMutableDictionary *myDic in dataArray) {
           CategorDetail *cateD =[[CategorDetail alloc]init];
           cateD.singer_name =[myDic objectForKey:@"singerName"];
           cateD.song_name =[myDic objectForKey:@"name"];
           cateD.mvList =[myDic objectForKey:@"mvList"];
           cateD.outList =[myDic objectForKey:@"outList"];
           cateD.album_name =[myDic objectForKey:@"albumName"];
           cateD.audition_list =[myDic objectForKey:@"auditionList"];
    
           for (NSMutableDictionary *mvListDIC in cateD.mvList) {
                cateD.url =[mvListDIC objectForKey:@"url"];
               cateD.pic_url =[mvListDIC objectForKey:@"picUrl"];
               NSURL *url =[NSURL URLWithString:cateD.pic_url];
               [self.imageView sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"cm2_default_artist_banner-1"]];
               [self.myImageView sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"cm2_default_artist_banner-1"]];

           }
         
           
           [self.myArray addObject:cateD];
           [cateD release];
             [self.HUD hide:YES];
           
           
           
       }
       [self.myTableView reloadData];
       
        
    }];
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

   
    PlayingViewController *playVC = [PlayingViewController shareHandleController];
    playVC.array = self.myArray ;
    playVC.indexPath = indexPath.row;
    [self.myTableView deselectRowAtIndexPath:indexPath animated:YES];
    UINavigationController *naPlayVC = [[UINavigationController alloc]initWithRootViewController:playVC];
    [self presentViewController:naPlayVC animated:YES completion:^{
        
        
    }];

}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    return self.myArray.count;
}


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIndentifier =@"cell";
    CategorTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIndentifier];
    if (cell == nil) {
        cell = [[CategorTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIndentifier];
    }
  
    cell.categor =[self.myArray objectAtIndex:indexPath.row];
    cell.numberLabel.text =[NSString stringWithFormat:@"%ld",indexPath.row+1];
    
    cell.layer.transform = CATransform3DMakeScale(0.3, 0.3, 0.1);
    [UIView animateWithDuration:0.5 animations:^{
        
        cell.layer.transform = CATransform3DMakeScale(1, 1, 0.1);
  
    }];
    
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 100;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
